define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'adminlte', 'template'], function ($, undefined, Backend, Table, Form, Adminlte, Template) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'dormitory/album/index',
                    add_url: '',
                    edit_url: '',
                    del_url: '',
                    multi_url: '',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                sortName: 'image_count',
                sortOrder: 'desc',
                columns: [
                    [

                        {field: 'state', checkbox: true, },
                        {
                            field: 'a.number', title: __('园区'), searchList: function (column) {
                                return Template('gardenTpl', {});
                            }, formatter: function (value, row, index) {
                                return '无';
                            }, visible: false
                        },
                        {field: 'garden_name', title: __('园区'), operate: false},
                        {field: 'building_name', title: __('楼栋'), operate: false},
                        {field: 'number', title: __('寝室号'), operate: false},
                        {field: 'image_count', title: __('图片数量'), operate: false},
                        {
                            field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, buttons: [
                                {
                                    name: 'detail',
                                    title: '查看',
                                    text: '查看',
                                    icon: 'fa fa-heart',
                                    classname: 'btn btn-success btn-xs btn-click',
                                    click: function (e, data) {
                                        //Backend.api.addtabs('dormitory/image/detail/ids/' + data.id, '查看');
                                        Backend.api.open('dormitory/image/detail/ids/' + data.id, __('查看'), {area: ['70%', '80%']});
                                    }
                                },
                            ], formatter: Table.api.formatter.operate
                        }
                    ]
                ],
                commonSearch: true,
                searchFormVisible: true,
            });

            // 为表格绑定事件
            Table.api.bindevent(table);

            // 监听下拉列表改变的事件
            $(document).on('change', 'select[name=garden_number]', function () {
                $("#garden_number").val($(this).val());
            });
            // 监听下拉列表改变的事件
            $(document).on('change', 'select[name=building_number]', function () {
                $("#building_number").val($(this).val());
            });

        },

        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});